<!-- 完成吸顶头部 -->
<template>
  <div class="app-header-sticky" :class="{ show: scrollTop > 80 }">
    <div class="container" v-show="scrollTop >= 80">
      <router-link class="logo" to="/" />
      <HeaderNavVue />
      <div class="right">
        <router-link to="/">品牌</router-link>
        <router-link to="/">专题</router-link>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, onMounted, ref } from 'vue'
import { useWindowScroll } from "@vueuse/core"
import HeaderNavVue from './header-nav.vue'

export default defineComponent({
  name: "AppHeaderSticky",
  // setup() {
  //   //使用原生方式来获取滚动高度
  //   const scrollTop = ref(0)
  //   onMounted(() => {
  //     window.onscroll = e => {
  //       scrollTop.value = document.documentElement.scrollTop
  //     }
  //   })
  //   return {
  //     scrollTop
  //   }
  // },


  setup() {
    const { y: scrollTop } = useWindowScroll()
    return {
      scrollTop
    }
  },

  components: {
    HeaderNavVue
  }
})
</script>

<style lang="less" scoped>
.app-header-sticky {
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
  transform: translateY(-100%);
  opacity: 0;

  &.show {
    // 达到指定位置的显示动画
    opacity: 1;
    transition: all 0.3s linear;
    transform: none;
  }

  .container {
    display: flex;
    align-items: center;
  }
  .logo {
    width: 200px;
    height: 80px;
    background: url(../assets/images/logo.png) no-repeat right 2px;
    background-size: 160px auto;
  }
  .right {
    width: 220px;
    display: flex;
    text-align: center;
    padding-left: 40px;
    border-left: 2px solid @xtxColor;
    a {
      width: 38px;
      margin-right: 40px;
      font-size: 16px;
      line-height: 1;
      &:hover {
        color: @xtxColor;
      }
    }
  }
}
</style>